#include <string.h>
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std::string;

void test0(){
    ifstream ifs("explicit.cc");
    //文件要存在，不存在会使ifs进入failbit状态

    if(!ifs){
        cerr << "ifstream open file failed!" << endl;
        return;
    }

    //方式一，兼容C的写法，工作中不常用
    char buff[100] = {0};
    while(ifs.getline(buff,sizeof(buff))){
        cout << buff << endl;
        memset(buff,0,sizeof(buff));
    }


    cout << endl;
    ifs.clear();
    ifs.seekg(0);

    if(ifs){
        cout << "hello" << endl << endl;
    }
    //方式二，比较常用
    string line;
    while(std::getline(ifs,line)){
        cout << line << endl;
    }

    //关闭文件输入流
    ifs.close();
}

int main(void){
    test0();
    return 0;
}
